***********************************************************************************************************************
* Replication code for "A Large-Scale Field Experiment to Reduce Non-Payments for Water: From Diagnosis to Treatment" *
***********************************************************************************************************************
* This program was run on Stata/SE 15.1 on a Mac personal computer.

** Make sure the following programs are installed. If not unmute the next four lines
* ssc install winsor 
* ssc install twopm  
* ssc install ebalance
* ssc install cem
* ssc install grubbs
* ssc install estout, replace


clear all
set more off
set seed 3125

global filepath "/Users/sebastiantonke/Desktop/Replication Package/Replication files experiment" // <----- set your filepath here

********************* Setting Subdirectories  ************************
global data  	"$filepath/data"
global dofiles	"$filepath/do_files"
global output	"$filepath/output_logs"
global temp		"$data/temp" 

********************** Preparing Dataset *****************************
do "$dofiles/data_preparation"

********************** Tables Main Text ******************************
do "$dofiles/table 1"
do "$dofiles/table 2"
do "$dofiles/table 3"
do "$dofiles/table 4"
do "$dofiles/table 5"

********************** Appendix Tables *******************************
do "$dofiles/table a1"
do "$dofiles/table a4"
do "$dofiles/table a9"
do "$dofiles/table a10"
do "$dofiles/table a13"
do "$dofiles/table a14"
do "$dofiles/table a15"
do "$dofiles/table a16"
do "$dofiles/table a17"
do "$dofiles/table a18"


********************** Appendix Figures ******************************
do "$dofiles/figure in a11"
do "$dofiles/figure a2"
do "$dofiles/figure a5"


****************** Other stats mentioned in text  ********************
do "$dofiles/other_stats"


********************** Appendix Simuation *******************************
* The simulation was run a windows computer using Stata 16.1 MP.
* Running this code might take 2-3 weeks to complete. If you want to reduce running time you can set the number of repetitions for the bootstrap in the twopm command line ("reps(1000)") to 2 instead of 1000.
do "$dofiles/table a12" 








